<template>
  <div class="execution">
    <basic-container>
      <avue-crud
                  :permission="permissionList"
                 v-model="form"
                 v-bind="bindVal"
                 v-on="onEvent"
                 :page.sync="page"
                 :before-open="beforeOpen"
                 :row-style="rowStyle">
        <template slot-scope="scope" slot="menuLeft">
          <el-button
            type="primary"
            size="small"
            v-permission="permissionList.receptionBtn"
            v-if="permissionList.receptionSub"
            @click="receptionSub()">接收
          </el-button>
          <el-button
            type="primary"
            size="small"
            v-permission="permissionList.receptionBtn"
            v-if="permissionList.handIn"
            @click="handIn()">上交
          </el-button>
          <el-button
            type="primary"
            size="small"
            v-permission="permissionList.receptionBtn"
            v-if="permissionList.integration"
            @click="integration()">配入
          </el-button>
          <el-button
            type="primary"
            size="small"
            v-permission="permissionList.notificationBtn"
            v-if="permissionList.notificationSub"
            @click="notificationSub()">通知
          </el-button>
        </template>
      </avue-crud>
    </basic-container>
  </div>
</template>

<script>
import {tableOption} from '@/const/crud/subwaystm/InvalidTicketManagement'
import {fetchList, updateStatus} from '@/api/subwaystm/InvalidTicketManagement'
import {mapGetters} from 'vuex'
import baseCrud from '@/mixins/base-crud'

export default {
  name: 'InvalidTicketManagement',
  mixins: [baseCrud('subwaystm/InvalidTicketManagement')],
  data() {
    return {
      searchForm: {
        invalidTicketConfirmStatus:'1'
      }
    }
  },
  computed: {
    ...mapGetters(['permissions']),
    permissionList() {
      return {
        receptionSub: this.vaildData(
          this.permissions.invalid_ticket_management_reception,
          false
        ),
        notificationSub: this.vaildData(
          this.permissions.invalid_ticket_management_notification,
          false
        ),
        handIn: this.vaildData(
          this.permissions.invalid_ticket_management_hand_in,
          false
        ),
        integration: this.vaildData(
          this.permissions.invalid_ticket_management_integration,
          false
        ),
        // receptionBtn: this.vaildData(this.permissions.invalid_ticket_management_reception, true),
        // notificationBtn: this.vaildData(this.permissions.invalid_ticket_management_notification, true)
      };
    }
  },
  methods: {
    // getList(page, params) {
    //   this.tableLoading = true
    //   fetchList(Object.assign({
    //     current: page.currentPage,
    //     size: page.pageSize
    //   }, params, this.searchForm )).then(response => {
    //     this.tableData = response.data.data.records
    //     this.page.total = response.data.data.total
    //     this.tableLoading = false
    //   })
    // },
    //接收
    receptionSub() {
      if (this.$refs.crud.tableSelect.length < 1) {
        this.$message.error("请选择数据");
        return false;
      }
      let ids = [];
      for (const table of this.$refs.crud.tableSelect) {
        if (table.invalidTicketConfirmStatus != 1){
          this.$message.error("数据非已发送状态！");
          return false;
        }
        table.diffCase=this.diffCase;
        ids.push(table.id)
      }
      let confirmStatus = 2;
      updateStatus(ids, confirmStatus).then(data => {
        this.$message.success('接收成功');
        this.batchReviewVisible=false;
        this.getList(this.page);
      }).catch(() => {
        this.$message.error("接收失败，请联系管理员处理");
        return false;
      })
    },
    //上交
    handIn() {
      if (this.$refs.crud.tableSelect.length < 1) {
        this.$message.error("请选择数据");
        return false;
      }
      let ids = [];
      for (const table of this.$refs.crud.tableSelect) {
        if (table.invalidTicketConfirmStatus != 2){
          this.$message.error("数据非已接收状态！");
          return false;
        }
        table.diffCase=this.diffCase;
        ids.push(table.id)
      }
      let confirmStatus = 6;
      updateStatus(ids, confirmStatus).then(data => {
        this.$message.success('上交成功');
        this.batchReviewVisible=false;
        this.getList(this.page);
      }).catch(() => {
        this.$message.error("上交失败，请联系管理员处理");
        return false;
      })
    },
    //配入
    integration() {
      if (this.$refs.crud.tableSelect.length < 1) {
        this.$message.error("请选择数据");
        return false;
      }
      let ids = [];
      for (const table of this.$refs.crud.tableSelect) {
        if (table.invalidTicketConfirmStatus != 6){
          this.$message.error("数据非已上交状态！");
          return false;
        }
        table.diffCase=this.diffCase;
        ids.push(table.id)
      }
      let confirmStatus = 7;
      updateStatus(ids, confirmStatus).then(data => {
        this.$message.success('配入成功');
        this.batchReviewVisible=false;
        this.getList(this.page);
      }).catch(() => {
        this.$message.error("配入失败，请联系管理员处理");
        return false;
      })
    },
    //通知
    notificationSub(){
      if (this.$refs.crud.tableSelect.length < 1) {
        this.$message.error("请选择数据");
        return false;
      }
      let ids = [];
      for (const table of this.$refs.crud.tableSelect) {
        if (table.invalidTicketConfirmStatus != 7){
          this.$message.error("数据非已配入状态！");
          return false;
        }
        table.diffCase=this.diffCase;
        ids.push(table.id)
      }
      let confirmStatus = 3;
      updateStatus(ids, confirmStatus).then(data => {
        this.$message.success('通知成功');
        this.batchReviewVisible=false;
        this.getList(this.page);
      }).catch(() => {
        this.$message.error("通知失败，请联系管理员处理");
        return false;
      })
    },

    // searchChange(form) {
    //   this.searchForm = form
    //   this.getList(this.page, form)
    // },
    // refreshChange() {
    //   this.getList(this.page)
    // }
  }
}
</script>
<style lang="scss" scoped>
.bottom-menu {
  text-align: center;
}
</style>
